package chapter4.lokup_method_injection;

import org.springframework.context.support.GenericXmlApplicationContext;
import org.springframework.util.StopWatch;

public class LookupDemo {
	public static void displayInfo(DemoBean bean) {
		MyHelper myHelper1 = bean.getMyHelper();
		MyHelper myHelper2 = bean.getMyHelper();

		System.out.println("Helper Instances the Same?: "
				+ (myHelper1 == myHelper2));

		StopWatch stopWatch = new StopWatch();
		stopWatch.start("lookupDemo");
		for (int x = 0; x < 100000; x++) {
			MyHelper helper = bean.getMyHelper();
			helper.doSomethingHelpful();
		}
		stopWatch.stop();
		System.out.println("100000 gets took " + stopWatch.getTotalTimeMillis()
				+ " ms");
	}

	public static void main(String[] args) {
		GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
		ctx.load("classpath:chapter4/lokup_method_injection/lookup.xml");
		DemoBean abstractBean = (DemoBean) ctx.getBean("abstractLookupBean");
		DemoBean standardBean = (DemoBean) ctx.getBean("standardLookupBean");
		displayInfo(standardBean);
		displayInfo(abstractBean);
	}
}
